/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Symmetric2x2StrategyComponent.java
 *
 * Created on 18/Dez/2011, 15:56:04
 */

package intopo.game.impl.sym2x2;

import intopo.game.gui.AbstractStrategyEditorComponent;
import intopo.game.gui.ParsingException;

/**
 *
 * @author <a href="mailto:mariano.pedro@gmail.com">Pedro Mariano</a>
 *
 * @version 1.0 18/Dez/2011
 */
public class Symmetric2x2StrategyComponent
	extends AbstractStrategyEditorComponent<Symmetric2x2Strategy>
{
	private int error;
	/** Creates new form BeanForm */
	public Symmetric2x2StrategyComponent ()
	{
		this.error = 0;
		initComponents();
	}
	@Override
	public String getConfigFileDescription () {
		throw new UnsupportedOperationException ("Not supported yet.");
	}

	@Override
	public Symmetric2x2Strategy getStrategy ()
	{
		if (error == 0) {
			return new Symmetric2x2Strategy ((Float) this.firstActionProbabilityFormattedTextField.getValue ());
		}
		else {
			return null;
		}
	}

	@Override
	public void setStrategy (Symmetric2x2Strategy strategy)
	{
		this.firstActionProbabilityFormattedTextField.setValue (new Float (strategy.firstActionProbability));
	}

	/** This method is called from within the constructor to
	 * initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
    @SuppressWarnings("unchecked")
   // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
   private void initComponents() {
      java.awt.GridBagConstraints gridBagConstraints;

      firstActionProbabilityFormattedTextField = new javax.swing.JFormattedTextField();
      javax.swing.JLabel jLabel1 = new javax.swing.JLabel();

      setLayout(new java.awt.GridBagLayout());

      firstActionProbabilityFormattedTextField.setColumns(5);
      firstActionProbabilityFormattedTextField.setValue(new Float (0.5f));
      firstActionProbabilityFormattedTextField.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
         public void propertyChange(java.beans.PropertyChangeEvent evt) {
            firstActionProbabilityFormattedTextFieldPropertyChange(evt);
         }
      });
      gridBagConstraints = new java.awt.GridBagConstraints();
      gridBagConstraints.gridx = 1;
      add(firstActionProbabilityFormattedTextField, gridBagConstraints);

      jLabel1.setText("First action probability: ");
      gridBagConstraints = new java.awt.GridBagConstraints();
      gridBagConstraints.gridx = 0;
      gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
      add(jLabel1, gridBagConstraints);
   }// </editor-fold>//GEN-END:initComponents

	 private void firstActionProbabilityFormattedTextFieldPropertyChange (java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_firstActionProbabilityFormattedTextFieldPropertyChange
		 if (evt.getPropertyName ().equals ("value")) {
			 final float value = (Float) this.firstActionProbabilityFormattedTextField.getValue ();
			 final boolean ok = value >= 0 && value <= 1;
			 if (ok) {
				 error |= ~1;
			 } else {
				 error &= 1;
			 }
			 this.update (this.firstActionProbabilityFormattedTextField, ok);
		 }
}//GEN-LAST:event_firstActionProbabilityFormattedTextFieldPropertyChange


   // Variables declaration - do not modify//GEN-BEGIN:variables
   private javax.swing.JFormattedTextField firstActionProbabilityFormattedTextField;
   // End of variables declaration//GEN-END:variables

}

// Local Variables:
// mode: java
// mode: flyspell-prog
// ispell-local-dictionary: "british"
// End:
